import {
  CreateDateColumn,
  UpdateDateColumn,
  BaseEntity as TypeOrmBaseEntity,
  PrimaryColumn,
  BeforeInsert,
} from 'typeorm';
import { GenerateUUID } from '@/utils/uuid';

export abstract class BasePo extends TypeOrmBaseEntity {
  @PrimaryColumn({ type: 'varchar', length: 32 })
  id: string;

  @CreateDateColumn({ name: 'created_at' })
  createTime: Date;

  @UpdateDateColumn({ name: 'updated_at' })
  updateTime: Date;

  @BeforeInsert()
  generateId() {
    this.id = GenerateUUID();
  }
}
